<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8"/>
    <title>PHP IO丐中丐留言板</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div style="display: flex;justify-content: center;margin-top: 50px">
    <form action="data.php" method="GET">
        <table border="3" class="NewTab">
            <tr>
                <th colspan="3"><a href="https://gitee.com/KcanyueL/php-io-message-board">PHP IO留言板</a></th>
            </tr>
            <tr>
                <th>留言人:</th>
                <td colspan="2"><input style="width: 97%;font-size: 1.2em" type="text" name="name"></td>
            </tr>
            <tr>
                <th>内容:</th>
                <td colspan="2"><textarea style="width: 98%;height: 300px;font-size: 150%" name="body"></textarea></td>
            </tr>
            <tr>
                <th colspan="3">
                    <input style="align-items: center" type="submit" value="提交">
                    <input style="align-items: center;margin-left: 15px" type="reset" value="清屏">
                </th>
            </tr>
            <?php
            date_default_timezone_set('PRC');
            $ctrlIn = fopen("saveData.txt", "a+");
            $res = $_GET["name"].",".$_GET["body"].",".date("Y-m-d H:i:s");
            if($_GET["name"] != null && $_GET["body"] != null){
                fwrite($ctrlIn, $res . "\n");
            }
            fclose($ctrlIn);
            ?>
            <tr>
                <th colspan="3">留言记录</th>
            </tr>
            <?php
            $ctrlOut = fopen("saveData.txt", "r");
            $i = 0;
            while (($Out = fgetcsv($ctrlOut)) != false) {
                echo "<tr><th>".$Out[0]."</th><td width='150px'>". $Out[1]."</td><td>". $Out[2] . "</td></tr>";
                $i++;
            }
            fclose($ctrlOut);
            ?>
            <tr>
                <th colspan="3"><a href="https://gitee.com/KcanyueL">-----21软件技术2班22刘开利-----</a></th>
            </tr>
        </table>
    </form>
</div>

</body>
</html>

<style>
    .NewTab {
        border-collapse: collapse;
    }

    .NewTab tr, .NewTab td, .NewTab th {
        text-align: center;
        border: 1px solid #BBBBBB;
    }

    .NewTab th {
        background-color: #E6E6E6;
    }

    .NewTab tr:hover {
        background-color: #EEEEEE;
    }

    .NewTab td, .NewTab th {
        padding: 10px;
    }
</style>
